#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>

struct node {
	int val;
	struct node *next;
};

struct node *
qsort_llist(struct node *root)
{
	int pivot = root->val;
	struct node *cur, *lo, *lo_last, *hi, *hi_last;
	struct node *eq, *eq_last;

	if (root == NULL || root->next == NULL)
		return 0;

	cur = root;
	eq = eq_last = lo = lo_last = hi = hi_last = NULL;
	while (cur) {
		if (cur->val < pivot) {
			if (!(lo && lo_last)) {
				lo = lo_last = cur;
				cur = cur->next;
				lo->next = NULL;
			} else {
				lo_last->next = cur;
				cur = cur->next;
				lo_last = lo_last->next;
				lo_last->next = NULL;
			}
		} else if (cur->val > pivot) {
			if (!(hi && hi_last)) {
				hi = hi_last = cur;
				cur = cur->next;
				hi->next = NULL;
			} else {
				hi_last->next = cur;
				cur = cur->next;
				hi_last = hi_last->next;
				hi_last->next = NULL;
			}
		} else {
			if (!(eq && eq_last)) {
				eq = eq_last = cur;
				cur = cur->next;
				eq->next = NULL;
			} else {
				eq_last->next = cur;
				cur = cur->next;
				eq_last = eq_last->next;
				eq_last->next = NULL;
			}
		}
	}

	qsort_llist(lo);
	qsort_llist(hi);

	for (lo_last = lo; lo_last->next; lo_last = lo_last->next);
	lo_last->next = eq;
	eq_last->next = hi;

	return 0;
}

int
main(int argc, char **argv)
{
	int n;
	struct node *root, *nd, *prev;
	int i = 0;

	scanf("%d", &n);
	root = prev = nd = malloc(sizeof *root);
	while (i++ < n) {
		scanf("%d", &nd->val);
		nd->next = malloc(sizeof *nd);
		prev = nd;
		nd = nd->next;
		nd->next = NULL;
	}
	free(nd);
	prev->next = NULL;

	qsort_llist(root);

	nd = root;
	while (nd) {
		printf("%d ", nd->val);
		nd = nd->next;
	}
	fputc('\n', stdout);

	nd = root;
	while (nd) {
		nd = root;
		root = root->next;
		free(nd);
	}
	return 0;
}
